// ====================EffectCardSprite====================

class Sprite_EffectCard extends Sprite_Card {
    initialize(opts) {
        super.initialize(opts);
        this.anchor.set(0.5, 1);
        this._eventListener = {};
        this._enter = null;
        this.context = {}
    }

    clear() {
        this._enter = null;
        this.context = {}
        this.clearAnimation();
        this.clearAllEventListener();
        this.setPopular();
    }

    addEventListener(type, listener) {
        const eventListener = this._eventListener[type];
        if (!eventListener) this._eventListener[type] = [];
        this._eventListener[type].push(listener);
    }

    clearEventListener(type) {
        const eventListener = this._eventListener[type];
        if (!!eventListener) delete this._eventListener[type];
    }

    clearAllEventListener() {
        this._eventListener = {};
    }

    update() {
        super.update();
        if (CardGameManager.isAnyWindowOpen()) return;
        const state = this.hitTest();
        const oldState = this._enter;
        this._enter = state;
        if (oldState === null) return;
        // 先判定点击事件
        if (TouchInput.isClicked() && state) {
            const listeners = this._eventListener["onClick"];
            if (!!listeners) {
                for (const listener of listeners) {
                    listener(this);
                }
            }
        }
        // 再判定进出事件
        if (state !== oldState) {
            const listeners = !!state ? this._eventListener["onEnter"] : this._eventListener["onExit"];
            if (!!listeners) {
                for (const listener of listeners) {
                    listener(this);
                }
            }
        }
    }
}